package com.nuoniu.sibanyun.mapper.po;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.erp.ErpInvoiceType;
import com.nuoniu.sibanyun.entity.po.VPurchaseInvoiceMain;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 采购发票主表 Mapper 接口
 * </p>
 *
 * @author 小啊刚
 * @since 2020-11-19
 */
public interface VPurchaseInvoiceMainMapper extends BaseMapper<VPurchaseInvoiceMain> {

    @Select("select voucher_code from scp_invoice where company_id=#{companyId} and date_format(create_date, #{dateStr})=date_format(now(), #{dateStr}) AND data_source = #{dataSource} order by create_date desc limit 1")
    String getNewestCode(Integer companyId, String dateStr, String dataSource);

    @Select("select * from scp_invoice where source_voucher_code=#{voucherCode}")
    List<VPurchaseInvoiceMain> getBySourceCode(String voucherCode);

    /**
     * 根据发票类型统计
     * @author 小啊刚
     * @date 2021-02-06
     */
    @Select("select count(1) from scp_invoice where invoice_type_id in (${ids})")
    Integer getByInvoiceType(String ids);

    /**
     * 修改发票类型
     * @author 小啊刚
     * @date 2021-02-06
     */
    @Update("update scp_invoice set invoice_type_name=#{name} where invoice_type_id=#{id}")
    void updateInvoiceType(ErpInvoiceType invoiceType);
}
